package cn.farm.farm.Mapper.CommonMapper;

import cn.farm.farm.Entity.Common.Image;
import cn.farm.farm.Entity.Common.Plant;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface PlantMapper extends Mapper<Plant> {
    @Select("select plantID,chineseName,latinName,alias,plantImage from plant where chineseName like CONCAT('%',#{name},'%')")
    @Results({
            @Result(column = "plantImage" , property = "plantimage",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    List<Plant> likeSelect(@Param(value = "name") String name);

    @Select("select * from plant where plantID =#{plantid}")
    @Results({
            @Result(column = "plantImage" , property = "plantimage",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    Plant selectByKey(@Param(value = "plantid") Integer plantid);

    @Select("select count(*) from plant where category in (select bioID from biologycategory where species = #{species}) ")
    Integer selectByCate(@Param(value = "species") String species);

    @Select("select plantID,chineseName,latinName,alias,plantImage from plant where category in (select bioID from biologycategory where species = #{species} ) ")
    @Results({
            @Result(column = "plantImage" , property = "plantimage",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    List<Plant> selectByCategory(@Param(value = "species") String species);

    @Select("select * from file where imageID in (select imageID from match_image where matchID = (select plantImage from plant where plantID = #{plantid}))")
    List<Image> selectImage(@Param(value = "plantid") Integer plantid);

}
